package com.rmlowe.tincan;

import static com.rmlowe.tincan.Statement.parse;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;

import java.io.IOException;
import java.net.URI;

import junit.framework.Assert;

import org.junit.Test;

public final class StatementTest {
	@Test
	public final void testIdNotNull() throws IOException {
		assertEquals("fd41c918-b88b-4b20-a0a5-a4c32391aaa0",
				parse(StatementTest.class
						.getResourceAsStream("statement1.json")).id);
	}

	@Test
	public final void testIdNull() throws IOException {
		assertNull(parse(StatementTest.class
				.getResourceAsStream("simplest.json")).id);
	}

	@Test
	public final void testActorObjectType() throws IOException {
		Assert.assertSame(ObjectType.AGENT, parse(StatementTest.class
				.getResourceAsStream("statement1.json")).actor.objectType);
	}

	@Test
	public final void testActorNameNotNull() throws IOException {
		assertEquals("Project Tin Can",
				parse(StatementTest.class
						.getResourceAsStream("statement1.json")).actor.name);
	}

	@Test
	public final void testActorNameNull() throws IOException {
		assertNull(parse(StatementTest.class
				.getResourceAsStream("simplest.json")).actor.name);
	}

	@Test
	public final void testActorMbox1() throws IOException {
		assertEquals("mailto:tincan@adlnet.gov",
				parse(StatementTest.class
						.getResourceAsStream("statement1.json")).actor.mbox);
	}

	@Test
	public final void testActorMbox2() throws IOException {
		assertEquals(
				"mailto:xapi@adlnet.gov",
				parse(StatementTest.class.getResourceAsStream("simplest.json")).actor.mbox);
	}

	@Test
	public final void testVerbId() throws IOException {
		/*
		 * Source:
		 * http://www.tincanapi.co.uk/wiki/Guide:Tin_Can_Learning_Evaluator
		 * #Evaluating_and_Reflecting
		 */
		assertEquals(
				URI.create("http://www.tincanapi.co.uk/wiki/verbs:evaluated"),
				parse(StatementTest.class
						.getResourceAsStream("Tin Can Learning Evaluator 1.json")).verb.id);
	}
}
